package com.dome.common.pojo;


import java.util.Collection;

public class Pagination<T> {

    /**
     * 总页数
     */
    private long totalPageCount;

    /**
     * 当前页码
     */
    private int pageNo;

    /**
     * 页面大小（一页当中的数据条目数量）
     */
    private int pageSize;

    /**
     * 总数据条目数
     */
    private long totalItemCount;

    private Collection<T> data;

    public Pagination() {
        this.pageSize = 10;
        this.pageNo = 1;
        this.totalPageCount = 1;
    }

    public Pagination(Integer pageNo) {
        this();
        if (pageNo != null) {
            this.setPageNo(pageNo);
        }
    }

    public Pagination(Integer pageNo, Integer pageSize) {
        this(pageNo);
        if (pageSize != null) {
            this.setPageSize(pageSize);
        }
    }

    public void setTotalItemCount(Long itemCount) {
        if (itemCount != null) {
            this.totalItemCount = itemCount;
            this.totalPageCount = (itemCount + pageSize - 1) / pageSize;
            this.totalPageCount = totalPageCount <= 0 ? 1 : totalPageCount;
        }
    }

    public int getStart() {
        return pageSize * (pageNo - 1);
    }

    public long getTotalPageCount() {
        return totalPageCount;
    }

    public void setTotalPageCount(Long totalPageCount) {
        if (totalPageCount != null) {
            this.totalPageCount = totalPageCount < 1 ? 1 : totalPageCount;
        }
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        if (pageNo != null) {
            this.pageNo = pageNo < 1 ? 1 : pageNo;
        }
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        if (pageSize != null) {
            this.pageSize = pageSize;
        }
    }

    public long getTotalItemCount() {
        return totalItemCount;
    }

    public Collection<T> getData() {
        return data;
    }

    public void setData(Collection<T> data) {
        this.data = data;
    }

}
